const http = require('../../../utils/http.js');
const Net = require('../../../utils/common.js')
const Http = require('../../../Net')
Page({
  data: {
    list: [],
    titleTap: 1,
    is_login: false
  },
  onLoad: function (options) {
    var _this = this
    var sysinfo = wx.getSystemInfoSync(),
      statusHeight = sysinfo.statusBarHeight,
      isiOS = sysinfo.system.indexOf('iOS') > -1,
      navHeight;
    if (!isiOS) {
      navHeight = 48;
    } else {
      navHeight = 44;
    }
    _this.setData({
      status: statusHeight,
      navHeight: navHeight
    })
    // let options = {
    //   SDKAppID: 1400378574
    // };
    // let tim = TIM.create(options); 
    // tim.joinGroup({
    //   groupID: '@TGS#aKCQITSGH',
    //   type: 'TIM.TYPES.GRP_AVCHATROOM'
    // })
  },
  onTitleTap(e) {
    var _this = this
    _this.setData({
      titleTap: e.currentTarget.id
    })
  },
  onPageInfo() {
    var _this = this
    Net.link('v1/loginLive', {}, function (res) {
      console.log(res)
      _this.onLiveListInfo()
    }, 'GET', function (res) {}, 'live')

  },
  onLiveListInfo() {
    Net.link('v1/getLiveList', {
      page: 1
    }, function (res) {
      console.log(res)
      Net.data({
        list: res.data.data.live_list
      })
      wx.stopPullDownRefresh()
    }, 'GET', function (res) {}, 'live')
    Http.link('v1/user', {}, function (res) {
      console.log('判断是否登陆', res)
      if (res.data.code != 200) {
        wx.clearStorage()
        Net.data({
          is_login: true
        })
      } else {
        Net.data({
          is_login: false
        })
      }
    }, 'GET')
  },
  onPageListInfo(e) {
    // if (Net.data('is_login')) {
    //   wx.navigateTo({
    //     url: '/pages/Login/Index/index',
    //   })
    // } else {
    wx.navigateTo({
      url: '/pages/onNewPages/onLiveInfopage/onLiveInfopage?id=' + e.currentTarget.id,
    })
    // }
  },
  onReady: function () {},
  onShow: function () {
    var _this = this
    _this.onLiveListInfo()
  },
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {
    this.onLiveListInfo()
  },
  onReachBottom: function () {},
  onShareAppMessage: function () {}
})